import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class AMMinePage extends StatefulWidget {
  @override
  _AMMinePageState createState() => _AMMinePageState();
}

class _AMMinePageState extends State<AMMinePage> {
  @override
  Widget build(BuildContext context) {
    // 状态栏显示
    SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);

    return Scaffold(
      appBar: AppBar(
        title: Text(
          "我的",
          style: TextStyle(color: Colors.black),
        ),
        backgroundColor: Colors.white,
        elevation: 0,
      ),
      body: Container(
          color: Color(0xFFF0F0F0),
          child: Column(
            children: [
              _buildLine(),
              _buildUserInfo(),
              SizedBox(
                height: 10,
                width: double.infinity,
                child: Container(
                  color: Color(0xFFF0F0F0),
                ),
              ),
              _buildMedia(),
              SizedBox(
                height: 10,
                width: double.infinity,
                child: Container(
                  color: Color(0xFFF0F0F0),
                ),
              ),
              _buildSetting(),
            ],
          )),
    );
  }

  _buildUserInfo() {
    return GestureDetector(
      onTap: userInfoAction,
      child: Container(
        height: 100.0,
        padding: EdgeInsets.all(10),
        color: Colors.white,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            ///user_face.png
            Image.asset(
              'images/user_face.png',
              width: 60,
              height: 60,
            ),
            SizedBox(
              width: 15,
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "tom@test.com",
                  style: TextStyle(fontSize: 24),
                  textAlign: TextAlign.left,
                ),
                Text(
                  "超级用户",
                  style: TextStyle(fontSize: 16),
                  textAlign: TextAlign.left,
                )
              ],
            ),
            Expanded(
                child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Image.asset(
                  'images/into.png',
                  width: 28,
                  height: 28,
                ),
              ],
            )),
          ],
        ),
      ),
    );
  }

  _buildMedia() {
    return _buildItem("images/pic_manage.png", "多媒体设置", mediaAction);
  }

  _buildSetting() {
    return Column(
      children: [
        _buildItem("images/veriface.png", "视频设置", videoSettingAction),
        _buildItem("images/setting.png", "通用设置", generalSettingAction),
      ],
    );
  }

  Widget _buildItem(String iconName, String title, VoidCallback voidCallback) {
    return GestureDetector(
      onTap: voidCallback,
      child: Container(
        color: Colors.white,
        height: 50.0,
        padding: EdgeInsets.fromLTRB(10, 3, 10, 3),
        child: Row(
          children: [
            Image.asset(
              iconName,
              width: 28,
              height: 28,
            ),
            Padding(padding: EdgeInsets.fromLTRB(8, 0, 0, 8)),
            Text(
              title,
              style: TextStyle(fontSize: 16),
            ),
            Expanded(
                child: Container(
                    child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Image.asset(
                  'images/into.png',
                  width: 28,
                  height: 28,
                ),
              ],
            )))
          ],
        ),
      ),
    );
  }

  /// 点击多媒体中心
  void mediaAction() {
    print("多媒体中心");
  }

  /// 视频设置
  void videoSettingAction() {
    print("视频设置");
  }

  /// 通用设置
  void generalSettingAction() {
    print("通用设置");
  }

  /// 跳转用户中心
  void userInfoAction() {
    Navigator.of(context).pushNamed("/userInfo");
  }

  _buildLine() {
    return Container(
      height: 1,
      color: Color(0xFFF0F0F0),
    );
  }
}
